#include "guiterm.hpp"
#ifndef TERMINALLAYOUT_HPP
#define TERMINALLAYOUT_HPP

class TerminalLayout
	:public QLayout
{
	Q_OBJECT
public:
	TerminalLayout(QScrollBar *scrollBar);
	~TerminalLayout();
	
	QSize sizeHint() const;
	QSize minimumSize() const;
	
	void addItem(QLayoutItem *item);
	QLayoutItem *itemAt(int index) const;
	QLayoutItem *takeAt(int index);
	int count() const;
	
	void setGeometry(const QRect &rect);
	
protected slots:
	void scroll(int offset);
	
protected:
	int getItemHeight(QLayoutItem *item, int width);
	void updateScroll(const QRect &rect);
	void placeContents(const QRect &rect);
	
	QScrollBar *scrollBar;
	int scrollOffset;
	
	QRect lastRect;
	int lastElementBottom;
	
	deque<QLayoutItem*> contents;
};

#endif
